<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.apache.shiro.SecurityUtils" %>
<%@ page import="com.topisv.tms.service.account.ShiroDbRealm.ShiroUser" %>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
<script type="text/javascript">
var filterParam = {};
var datatable_content;
	$(function() {
		$("#queryForm").validate();
		//初始化日期选择框
		var now = new Date();
		var today = (now.getFullYear())
				+ "/"
				+ (now.getMonth() <9? "0" + (now.getMonth() + 1) : (now
						.getMonth() + 1)) + "/"
				+ (now.getDate() < 10 ? "0" + now.getDate() : now.getDate());
		$("#_dataRange").val(today + "-" + today);
		$("#_dataRange").daterangepicker({
			format : 'YYYY/MM/DD',
			dateLimit : {
				days : 31
			}
		});
	})
	
	
	function initTable(){
		datatable_content=$("#contentTable").dataTable({
	           "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/orderExport/queryOrder',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	            "aoColumns": [ 
	                    {"mData": null,
	                    	 "mRender": function (data, display, row) {
			              		<c:forEach items="${customerList}" var="customer">
									if("${customer.customerCode}" == row.customerCode){
										return "${customer.customerName}";
									}
								</c:forEach>
								return "";
				           }
	                    },
	                    {
	                      "mData": 'order',
	                      "render":function(obj){
	                        return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj.ordeno+"' title='查看订单信息' target='_blank'>"+obj.ordeno+"</a>";
	                      }
	                    },
	                    {"mData": 'customerOrderno'},
	                    {"mData": 'fromno'},
	                    {"mData": 'expressNo',
	                     "render":function(obj,type,full){
	                    	return full.expressNo||full.ebillNo;
	                    }},
	                    {
	                      "mData": 'billType',
	                      "render": function (obj) {
	                         var billType=obj;
	                         if(billType=='cbill'){
	                           return "普通面单";
	                         }else if(billType=='ebill'){
	                           return "电子面单";
	                         }else{
	                           return "";
	                         }
	                      }
	                    },
	                    {"mData": null,
	                    	 "mRender": function (data, display, row) {
			              		<c:forEach items="${warehouseList}" var="warehouse">
									if("${warehouse.groupCode}" == row.warehouseCode){
										return "${warehouse.groupName}";
									}
								</c:forEach>
								return "";
				           }
	                    },
	                    {"mData": 'batchCode',
	                     "render":function(obj){
	                            return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
	                      }
	                    },
	                    {"mData": 'taskCode',
	                     "render":function(obj){
	                            return "<a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode="+obj+"' title='查看任务信息' target='_blank'>"+obj+"</a>";
	                       }
	                    },
	                    {"mData": 'expressCompany'},
	                    {
	                      "mData": 'status',
	                      "render": function (obj) {
	                         var status=obj;
	                         if(status=='1'){
	                           return "创建批次";
	                         }else if(status=='2'){
	                           return "创建任务";
	                         }else if(status=='3'){
	                           return "已拣货";
	                         }else if(status=='4'){
	                           return "已灯光拣选";
	                         }else if(status=='5'){
	                           return "已包装";
	                         }else if(status=='6'){
	                           return "已发货";
	                         }else if(status=='9'){
	                           return "待包装";
	                         }else if(status=='0'){
	                           return "待创建批次";
	                         }else{
	                           return "";
	                         }
	                      }
	                    }
	             ]
	        });
	}
	function filter(item){
		filterParam[item.name] = item;
	}
	
	function callback(sSource, aoData, fnCallback ) {
	   	/* var formParam = $("#queryForm").serializeArray();
		for(var n in filterParam){
			formParam.push(filterParam[n]);
		} */
		aoData.push({"name" : "customerCode","value" : $("#_customerCode").val()});
		aoData.push({"name" : "warehouseCode","value" : $("#_warehouseCode").val()});
		aoData.push({"name" : "orderno","value" : $("#_orderno").val()});
		aoData.push({"name" : "status","value" : $("#_status").val()});
		aoData.push({"name" : "dataRange","value" : $("#_dataRange").val()});
		aoData.push({"name" : "logistics","value" : $("#_logistics").val()});
		aoData.push({"name" : "mailNo","value" : $("#_mailNo").val()});
		aoData.push({"name" : "batchCode","value" : $("#_batchCode").val()});
		aoData.push({"name" : "taskCode","value" : $("#_taskCode").val()});
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": fnCallback  
	   });
	}
	//查询
	function query() {
		if (datatable_content) {
			datatable_content.fnDestroy();
		}
		initTable();
	}
	
	//导出excel
	function exportExcel(){
		if($("#_customerCode").val().length == 0){
			alert("请选择商家...") ; 
			return ;
		}
		if($("#_warehouseCode").val().length == 0){
			alert("请选择仓库...") ; 
			return ;
		}
		$("#queryForm").attr("action","${ctx}/v2/orderExport/exportExcel");
		$("#queryForm").submit();
	}
</script>
</head>

<body>
<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>

<section class="content">
    <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
				    <form class="form-search" id="queryForm" method="post" >
				    <!-- 第一行 -->
					<div class="form-group row">
					
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 商家： </span> 
								<select data-placeholder="请选择..." class="form-control searchSelect" id="_customerCode" name="_customerCode" onchange="ajaxAreaGroup(this,'_warehouseCode')">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
											<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 仓库： </span> 
								<select class="form-control span3" id="_warehouseCode" name="_warehouseCode"  value = "HZTT">
									<option value="HZTT">杭州仓</option>
									<c:forEach items="${warehouseList}" var="warehouse">
										<option value="${warehouse.groupCode}" >${warehouse.groupName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 订单编号： </span> 
								<input type="text" class="form-control" id="_orderno" name="_orderno">
							</div>
						</div>
						
						<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
								<span class="input-group-text">订单状态:</span>
								<!--  TODO 修改批次状态值 -->
								<!-- 批次状态 (1.已创建批次 2.已创建任务 3.已拣货 4.已包装  5.已发货) -->
								<select  class="form-control" id="_status" name="_status"  value = "2">
										 <option value="2" <c:if test="${param._status eq '2'}">selected="selected"</c:if>>创建任务</option>
								        <option value="1" <c:if test="${param._status eq '1'}">selected="selected"</c:if>>创建批次</option>
								        <option value="3" <c:if test="${param._status eq '3'}">selected="selected"</c:if>>已拣货</option>
								        <option value="4" <c:if test="${param._status eq '4'}">selected="selected"</c:if>>已灯光拣选</option>
								        <option value="5" <c:if test="${param._status eq '5'}">selected="selected"</c:if>>已包装</option>
								        <option value="9" <c:if test="${param._status eq '9'}">selected="selected"</c:if>>待包装</option>
								        <option value="6" <c:if test="${param._status eq '6'}">selected="selected"</c:if>>已发货</option>
								</select> 
								</div>
						</div>
						
					</div>

                    <!-- 第二行 -->
					<div class=" form-group row">

						<div class="col-sm-6">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 日期范围： </span>

								<div class="input-group">
									<div class="input-group-addon">
										<i class="fa fa-calendar"></i>
									</div>
									<input type="text" class="form-control pull-right" id="_dataRange" name="_dataRange" value="${param._fromDate}"/>
								</div>
								
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 快递公司： </span> 
								<select class="form-control span3" id="_logistics" name="_logistics" value = "SF">
									<option value="SF">顺丰</option>
									<c:forEach items="${logisticsList}" var="logistics">
										<option value="${logistics.companyCode}" >${logistics.companyName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 快递单号： </span> 
								<select class="form-control span3" id="_mailNo" name="_mailNo"  value = "0">
								     <option value="0">未匹配</option>
								     <option value="">全部</option>
									<option value="1">已匹配</option>
								</select>
							</div>
						</div>
					</div>
					 <!-- 第三行 -->
					<div class=" form-group row">
					
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 作业批次： </span> 
								<input type="text" class="form-control" id="_batchCode" name="_batchCode">
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 作业任务： </span> 
								<input type="text" class="form-control" id="_taskCode" name="_taskCode">
							</div>
						</div>
						
						<div class="col-sm-3">
								<button class="btn btn-primary" type="button" onclick="query();">搜索</button>
								<button class="btn btn-info" type="button" onclick="exportExcel();">导出订单信息</button>
						</div>
					</div>
					</form>
				</div>

			</div>

	 </div>
	</div>
    <!-- 查询条件 end -->
  
    <!-- 查询结果 start -->
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 50px;">商家</th>
	        <th style="width: 100px;">能容订单号</th>
	        <th style="width: 100px;">商家订单号</th>
	        <th style="width: 100px;">来源订单号</th>
	        <th style="width: 100px;">快递单号</th>
	        <th style="width: 100px;">运单类型</th>
	        <th style="width: 50px;">仓库</th>
	        <th style="width: 100px;">作业批次</th>
	        <th style="width: 100px;">作业任务</th>
	        <th style="width: 100px;">快递公司</th>
	        <th style="width: 100px;">作业状态</th>
		</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div></div>
	</div>
	
	
	</section>
</body>
</html>